model={
    //任务列表，单个模型
    reportModel:'<a class="reportModel b_edge blockInline">' +
    '<section class="detailLine taskOne">' +
    '<section class="reportTittle"><span class="reportName"></span><span class="reportTag">报告</span></section>' +
    '<section class="repotType"><span class="TypeName" ></span></section>' +
    '</section>' +
    '<section class="reportImg"><img class="preImg"  src="" /></section>' +
    '<section class="reportDetail">' +
    '<section class="detailLine second"><span class="reportPioneer"></span></section>' +
    '<section class="second detailLine"><span class="c_tag">接收: </span> <span class="reportTime"></span>' +
    '</section>' +
    '</section>' +
    '</a>',
    moreRepotModel:'<a class="more-report-list b_edge blockInline">' +
    '<section class="more-report-Line-Info">' +
    '<section class="Line-tittle"><span class="report-tittle-name"></span><span class="report-tittle-phone"></span></section>' +
    '<section class="Line-time"><span class="reportTime"></span></section>' +
    '</section>' +
    '<section class="more-report-Line-img">' +
    '<img src="/resources/images/M_arrow.png">' +
    '</section>' +
    '</a>'
}


////////////////////////////////////////////////
// 基本任务列表
// 获取任务列表
function getReportList() {

    if(currentPage <= 0)
    {
        currentPage = 1;
        TotalPage   = 1;
    }
    else
    {
        if(currentPage >= TotalPage)
            return;

        currentPage++;
    }

    var url="/Report/reportList";
    var listener = reportListBack;
    var formdata={};

    formdata.pageNum    = currentPage;
    formdata.numPerPage = 10;
    formdata.version    = "1.2";
    formdata.uid        = currentUser.uid;
    formdata.findType   = 2;

    Request("POST",JSON.stringify(formdata),url,listener);
}

function reportListBack(resultObject){
    if( !resultObject || resultObject.code != 200) {
        if(currentPage <= 1)
        {
            $(".reportList").append('<span class="special_tag">查询失败，请返回重试.......</span>');
            $(".repoerListMore").css({
                display:"none"
            });
        }
    }
    else{
        var data=resultObject.data;
        if( !data ) {
            $(".reportList").append('<span class="special_tag">您暂时没有收到任务.......</span>');
        }

        var dataResult = data.recordList;

        currentPage = data.currentPage;
        TotalPage   = data.pageCount;

        if(currentPage < TotalPage)
        {
            getElem("idReportListMore").innerText = " 点击加载更多 "+currentPage+"/"+TotalPage;
            $(".repoerListMore").css({
                color:"#024c6e",
                display:"block"
            });
        }
        else
        {
            getElem("idReportListMore").innerText = "已经加载完毕";
            $(".repoerListMore").css({
                color:"#a0a0a0",
                display:"block"
            });
        }

        if( !dataResult || dataResult.length < 1)
        {
            if(currentPage <= 1)
            {
                $(".reportList").append('<span class="special_tag">您暂时没有收到任务.......</span>');
            }
            else
            {
                $(".reportList").append('<span class="special_tag">没有收到更多任务.......</span>');
            }

            return;
        }

        var one;
        //列表排序
        for(var i=0;i<dataResult.length;i++){
            for(var j=i+1;j<dataResult.length;j++)
                if(dataResult[j].rptTime > dataResult[i].rptTime){
                    one=dataResult[i];
                    dataResult[i]=dataResult[j];
                    dataResult[j]=one;
                }
        }

        var strImgURL = "";
        var strObject = "";
        var nType = 0;
        for(var i=0;i<dataResult.length;i++){
            var $mode=$(model.reportModel);
            var single=dataResult[i];

            //Image
            if(single.rptImg!=""&&single.rptImg!=null&&single.rptImg!=undefined)
            {
                strImgURL =  single.rptImg;
            }
            else
            {
                strImgURL =  "http://weixin.cepingjia.net/resources/images/moren.png";
            }

            $mode.find(".preImg").attr("src",strImgURL);
            $mode.find(".reportName").text(single.toolName);
            $mode.find(".reportTime").text(parseDate(new Date(single.rptTime)));

            strObject = single.taskObjectRemark;
            if(strObject.length <= 0)
            {
                strObject = single.userName;
                if(strObject.length <= 0 )
                {
                    strObject = currentUser.uname;
                }

                strObject =  "发起: " +  strObject;
            }
            else
            {
                strObject =  "对象: " +  strObject;
            }

            $mode.find(".reportPioneer").text(strObject);

            if(single.taskReportStyle == "2")
            {
                $mode.attr("href","/Report/moreReportRecover?taskID="+single.taskId +  "&uid=" + currentUser.uid + "&ImgUrl=" +strImgURL );
            }
            else
            {
                $mode.attr("href","/Report/transToReportDetail?taskID=" +single.taskId + "&rptId=" + single.rptId
                    + "&Uid=" + currentUser.uid
                    + "&toolId=" +single.toolId
                    + "&openId=" + currentUser.openId
                    + "&cid=" + currentUser.cid
                    + "&objRemark=" + encodeURI(encodeURI(strObject)));

                // $mode.attr("href",Report_URL+single.taskId +single.rptId + currentUser.uid + "00");
            }

            nType = single.toolLabel;
            if(nType == 2)
            {
                $mode.find(".TypeName").text("企业");
                $mode.find(".repotType").css({
                    backgroundColor:"#024c6e",
                    color:"#fff"
                });
            }
            else
            {
                $mode.find(".TypeName").text("个人");
                $mode.find(".repotType").css({
                    backgroundColor:"#f76900",
                    color:"#fff"
                });
            }

            $(".reportList").append($mode);
        }
    }
}


///////////////////////////
// 子表
function getMoreReportList()
{
    if(currentPage <= 0)
    {
        currentPage = 1;
        TotalPage   = 1;
    }
    else
    {
        if(currentPage >= TotalPage)
            return;

        currentPage++;
    }

    var url="/Report/moreReportList";
    var listener = moreReportListBack;
    var formdata={};

    formdata.pageNum    = currentPage;
    formdata.numPerPage = 15;
    formdata.uid        = currentUserId;
    formdata.taskId     = currentTaskId;

    Request("POST",JSON.stringify(formdata),url,listener);
}

function moreReportListBack(resultObject) {
    if( !resultObject || resultObject.code != 200) {
        if(currentPage <= 1)
        {
            if(resultObject.code == 404)
            {
                $(".reportList").append('<span class="special_tag">您暂时没有收到报告.......</span>');
            }
            else {
                $(".reportList").append('<span class="special_tag">查询失败，请返回重试.......</span>');
            }

            $(".repoerListMore").css({
                display:"none"
            });
        }
    }
    else{
        var data = resultObject.data;
        if( !data ) {
            $(".reportList").append('<span class="special_tag">您暂时没有收到报告.......</span>');
        }

        var dataResult = data.recordList;

        currentPage = data.currentPage;
        TotalPage   = data.pageCount;

        if(currentPage < TotalPage)
        {
            getElem("idReportListMore").innerText = " 点击加载更多 "+currentPage+"/"+TotalPage;
            $(".repoerListMore").css({
                color:"#024c6e",
                display:"block"
            });
        }
        else
        {
            getElem("idReportListMore").innerText = "已经加载完毕";
            $(".repoerListMore").css({
                color:"#a0a0a0",
                display:"block"
            });
        }

        if( !dataResult || dataResult.length < 1)
        {
            if(currentPage <= 1)
            {
                $(".reportList").append('<span class="special_tag">您暂时没有收到报告.......</span>');
            }
            else
            {
                $(".reportList").append('<span class="special_tag">没有收到更多报告.......</span>');
            }

            return;
        }

        var one;
        //列表排序
        for(var i=0;i<dataResult.length;i++){
            for(var j=i+1;j<dataResult.length;j++)
                if(dataResult[j].rptTime > dataResult[i].rptTime){
                    one=dataResult[i];
                    dataResult[i]=dataResult[j];
                    dataResult[j]=one;
                }
        }

        var strTemp = "";
        var nType = 0;
        for(var i=0;i<dataResult.length;i++){
            var $mode=$(model.moreRepotModel);
            var single=dataResult[i];

            $mode.attr("href",Report_URL +single.taRelaTaskId +single.taRelaReportId + currentUserId + "00");
            $mode.find(".reportTime").text(single.updateTime);

            $mode.find(".report-tittle-name").text(single.taRelaUname);

            strTemp = single.taRelaTel;
            if(strTemp && strTemp.length > 1)
            {
                $mode.find(".report-tittle-phone").text("("+strTemp+")");
            }

            $(".reportList").append($mode);
        }
    }
}